import os.path
import tornado.ioloop
import tornado.web
import tornado.httpserver
import tornado.options
from tornado.options import define, options

define("port", default=8000, help="run on the given port", type=int)


class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.render("index.html")


class UserHandler(tornado.web.RequestHandler):
    def post(self):
        user_name = self.get_argument("username", "")
        user_email = self.get_argument("email", "")
        user_website = self.get_argument("website", "")
        user_language = self.get_argument("language", "")
        self.render("user.html", username=user_name, email=user_email,
                    website=user_website, language=user_language)


handler = [
    (r"/", MainHandler),
    (r"/user", UserHandler)
]

template_path = os.path.join(os.path.dirname(__file__), "tornado")

if __name__ == "__main__":
    app = tornado.web.Application(handler, template_path)
    httpserver = tornado.httpserver.HTTPServer(app)
    httpserver.listen(options.port)
    # app.listen(options.port)
    tornado.ioloop.IOLoop.current().start()
    pass
